package com.hexiang.service;

import com.hexiang.BookServiceFacade;
import com.hexiang.entity.BookReqDto;
import com.hexiang.entity.ResultResponse;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import javax.validation.ValidationException;

/**
 * @author h01463
 * @version 1.0
 * @date 2024/7/26 15:48
 */
@Service
public class BookConsumerService {

    @DubboReference(timeout = 2000, retries = 1, interfaceName = "com.hexiang.BookServiceFacade")
    private BookServiceFacade bookServiceFacade;

    public ResultResponse createBook(BookReqDto bookReqDto) {
        ResultResponse resultResponse = new ResultResponse<>();
        try {
            resultResponse = bookServiceFacade.createBook(bookReqDto);
        } catch (Exception e) {
            if (e instanceof ValidationException) {
                ValidationException validationException = (ValidationException) e;
                resultResponse.setSucc(false);
                resultResponse.setMsg("参数校验异常");
            }
        }

        return resultResponse;
    }
}
